package com.zhifei.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhifei.common.utils.DateUtils;
import com.zhifei.common.utils.StringUtils;
import com.zhifei.system.domain.DingUserArchivesEntity;
import com.zhifei.system.domain.DingUserEntity;
import com.zhifei.system.domain.vo.DingUserDetailVo;
import com.zhifei.system.mapper.DingUserMapper;
import com.zhifei.system.service.DingUserArchivesService;
import com.zhifei.system.service.DingUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class DingUserServiceImpl extends ServiceImpl<DingUserMapper, DingUserEntity> implements DingUserService {

    @Autowired
    private DingUserMapper dingUserMapper;
    @Autowired
    private DingUserArchivesService dingUserArchivesService;

    @Override
    public DingUserEntity get(String userId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_id",userId);
        List<DingUserEntity> entityList = baseMapper.selectList(wrapper);
        return entityList.get(0);
    }

    @Override
    public void add(String userId, String deptId, DingUserDetailVo dingUserDetailVo) {
        DingUserEntity entity = new DingUserEntity();
        entity.setUserId(userId);
        entity.setJobNumber(dingUserDetailVo.getJobNumber());
        entity.setFullName(dingUserDetailVo.getUserName());
        entity.setUserPost(dingUserDetailVo.getPositionName());
        entity.setUserRank(dingUserDetailVo.getRankName());
        if(StringUtils.isNotEmpty(dingUserDetailVo.getMonthPay())){
            entity.setMonthPay(new BigDecimal(dingUserDetailVo.getMonthPay()));
        }
        entity.setDeptId(deptId);
        baseMapper.insert(entity);
    }

    @Override
    public void update(String userId, String deptId, DingUserDetailVo dingUserDetailVo) {
        this.lambdaUpdate()
                .set(DingUserEntity::getFullName,dingUserDetailVo.getUserName())
                .set(DingUserEntity::getUserPost,dingUserDetailVo.getPositionName())
                .set(DingUserEntity::getUserRank,dingUserDetailVo.getRankName())
                .set(DingUserEntity::getMonthPay,dingUserDetailVo.getMonthPay())
//                .set(DingUserEntity::getDeptId,deptId)
                .eq(DingUserEntity::getUserId,userId)
                .update();
    }

    @Override
    public void dismissUser(String jobNum, String dismissDate) {
        dingUserMapper.dismissUser(jobNum,dismissDate);
    }


}
